# -*- coding: utf-8 -*-
 
from django.shortcuts import render,HttpResponse,redirect
from BlogModel.models import Article
from django.conf import settings
from django.views.decorators.csrf import csrf_protect
import time
 
def index(request):
	blog_list = Article.objects.all()

	tag_list = Article.objects.values('art_tag').distinct()

	return render(request,'index.html',{'blog_list':blog_list,'tag_list':tag_list})


def content(request,param):
	params = int(param)

	blog_list = Article.objects.filter(id=params)

	tag_list = Article.objects.values('art_tag').distinct()

	return render(request,'content.html',{'blog_list':blog_list,'tag_list':tag_list})


def TagFind(request,param):
	params = param

	blog_list = Article.objects.filter(art_tag=params)

	tag_list = Article.objects.values('art_tag').distinct()

	return render(request,'index.html',{'blog_list':blog_list,'tag_list':tag_list})

def admin(request):

	return render(request,'admin.html')

def addArticle(request):

	req = request.POST

	art = Article(title=req['title'],article=req['content'],art_tag=req['tag'],timestamp=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

	art.save()

	return render(request,'admin.html')